data<-read.csv("figure3.csv",header=T,as.is=T)

data<-data[data$speaker_party=="democrat" | data$speaker_party=="republican",]
data$speaker_party <- factor(data$speaker_party, labels=c("Democrat","Republican"))
data <- data[data$prop<=1,]

midterm <- as.Date(c("1995-01-04","1999-01-06","2003-01-07","2007-01-04","2011-01-05","2015-01-06"))
presidential <- as.Date(c("1997-01-07","2001-01-03","2005-01-04","2009-01-06","2013-01-03","2017-01-03"))

data$speech_date <- as.Date(data$speech_date)

(p <- ggplot(data=data, aes(x=speech_date, y=prop,group=interaction(congress,speaker_party))) + 
		geom_point(alpha=.3, size=.1, aes(color=speaker_party)) +
		stat_smooth(aes(fill = speaker_party,color=speaker_party), span=5) + 
		xlab("Day") + 
		ylab("Proportion of Daily Speeches\nEngaing Bipartisanship")+
		#ggtitle("Calls for Bipartisanship in the US House of Representatives By Party (1995-2018)")+ 
		geom_vline(xintercept = presidential,color="black")+
		geom_vline(xintercept = midterm,color="gray")+ 
		geom_rect(data=data.frame(xmin=as.Date(c("1995-01-01","1997-01-07","2007-01-04","2011-01-06")),
								  xmax=as.Date(c("1997-01-06","2007-01-03","2011-01-05","2017-12-31")),
								  ymin=-Inf,
								  ymax=Inf),
				  aes(xmin=xmin,xmax=xmax,ymin=ymin,ymax=ymax),
				  fill=c("red","red","blue","red"),alpha=0.25,inherit.aes = FALSE) +
		scale_colour_manual(values=c("blue", "red")) + 
		scale_fill_manual(values=c("blue", "red")) +
		#xlim(as.Date("1990-01-01"),as.Date("2017-12-31")) +
		theme_pew()+ 
		theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
		theme(legend.position = "none") +
		coord_cartesian(ylim=c(0,.3), xlim=c(as.Date("1996-01-01"),as.Date("2016-12-31"))) +
		scale_x_date(date_breaks = "1 year", date_labels = "%Y"))

p
ggsave(filename="f3.pdf", plot=p,width=10,height=4)
